import { LOGGED_DOING, LOGGED_ERROR, LOGGED_IN } from './types';
import { login } from '../model/user';

export function loginByUserName() {
  return async (dispatch) => {
    dispatch({
      type: LOGGED_DOING
    });
    try {
      const data = await login();
      dispatch({ type: LOGGED_IN, data });
    } catch (error) {
      dispatch({ type: LOGGED_ERROR, error });
    }
  };
}
